import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;

public class MainWindow extends JFrame {
	public JButton btnRestart;
	public JTextArea infoArea;
	public JPanel field;

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public MainWindow(final String mode) {
		super();
		this.setSize(600, 600);
		this.setLayout(null);
		this.setTitle("Agent Assistence System");
		btnRestart = new JButton("Start");
		btnRestart.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent ae) {
				if (mode.equals("c") || mode.equals("d")) {
					String timeout = JOptionPane.showInputDialog(null,
							"Geben Sie eine Zeitdauer ein:", "Zeitdauer", 1);
					if (timeout != null) {
						try {
							Main.EVOLUTIONSDAUER = Integer.parseInt(timeout);
						} catch (NumberFormatException nfe) {
							Main.EVOLUTIONSDAUER = 10;
						}
						if (mode.equals("c")) {
							//btnRestart.setEnabled(false);
							field.invalidate();
							Main.c();
						} else if (mode.equals("d")) {
							//btnRestart.setEnabled(false);
							field.invalidate();
							Main.d();
						} 
					} else JOptionPane.showMessageDialog(null, "Sie müssen eine Zeitdauer angeben.", "Fehler", 1);
				} else if (mode.equals("a")) {
					field.invalidate();
					Main.a();
				} else if (mode.equals("b")) {
					field.invalidate();
					Main.b();
				}
			}
		});
		btnRestart.setBounds(420, 10, 160, 32);
		this.add(btnRestart);

		infoArea = new JTextArea("Infos: ");
		infoArea.setBounds(10, 420, 400, 100);
		infoArea.setEditable(false);
		this.add(infoArea);

		field = new JPanel();
		field.setBounds(10, 10, 400, 400);
		field.setBackground(Color.white);
		this.add(field);

		this.setVisible(true);
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
	}

}
